var page = 1;
var order = 1;

$(function($) {
	postData();
	//切换排序
	$(document)
		.on('click', '._order_opt', function() {
			var that = $(this);
			order = that.attr('data-type');
			//渲染数据
			postData();
		});
});

function postData() {
	$.post('/category/ajaxRecommentList.html', {
		page: 1,
		pagesize: 2,
		data_type: $('._data_type').val(),
		order: order
	}, getData)
}

function getData(data) {
	if(data.status == 200) { //渲染数据		
		$('body').animate({
					'scrollTop': 0
		}, 100);
		var html = template('category_list_content', data.data);
		document.getElementById('category_list_div').innerHTML = html;
		//分页
		if(data.data.totalpage != 1){
			$('._page').pagination({
				pageCount:data.data.totalpage,
				current:data.data.page,
				coping:true,
				callback:function(data){
					$.post('/category/ajaxRecommentList.html',{
						page:data.getCurrent(),
						pagesize:2,
						data_type: $('._data_type').val(),
						order: order
					},getData)
				}
			});
		}
	} else {
		toastr.error(data.msg, null, opts);
	}
}